unless defined?(RediPress)
  raise "You can't load this file. Please load the redipress file instead."
end

module RediPress
  # This class contains stuff related to SSH Keys
  #
  class SSHKeys
    # Load all SSH Keys stored in the user's SSH directory
    #
    # Example:
    #   >> RediPress::SSHKeys.load_ssh_keys
    #   => nil
    #
    def self.load_ssh_keys
      # Get the path to the user's personal SSH directory
      ssh_directory = File.join(Dir.home, ".ssh")

      # Return unless the SSH directory exists
      return nil unless File.directory?(ssh_directory)

      # Get the paths of all SSH Keys
      ssh_keys = Dir.glob(File.join(Dir.home, ".ssh", "*.pub")).map do |key|
      	File.join(File.dirname(key), File.basename(key, ".pub"))
      end

      # Adjust the configuration options for SSH Kit
      SSHKit::Backend::Netssh.configure do |ssh|
      	# Set the SSH options
      	ssh.ssh_options = {
      		# Set the SSH Keys to use when attempting to login to the remote host
      		keys: ssh_keys,

      		# Set the authentication methods
      		auth_methods: %w(publickey)
      	}
      end

      nil
    end
  end
end
